package com.fjb.config.listener;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent;
import org.apache.curator.framework.recipes.cache.PathChildrenCacheListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @Description:监听节点的所有子目录
 * @author hemiao
 * @time:2020年3月7日 下午4:34:42
 */
public class MyPathChildrenCacheListener implements PathChildrenCacheListener {
	
	private static final Logger log = LoggerFactory.getLogger(MyPathChildrenCacheListener.class);
	 
    @Override
    public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
    	log.info("-----> com.fjb.config.listener.MyPathChildrenCacheListener");
    	switch (event.getType()) {
            case INITIALIZED:
                //必须异步模式 PathChildrenCache.StartCollection.POST_INITIALIZED_EVENT
                log.info("子节点初始化成功");
                break;
            case CHILD_ADDED:
                log.info("添加子节点路径:" + event.getData().getPath());
                log.info("添加子节点数据:" + new String(event.getData().getData()));
                break;
            case CHILD_UPDATED:
                log.info("修改子节点路径:" + event.getData().getPath());
                log.info("修改子节点数据:" + new String(event.getData().getData()));
                break;
            case CHILD_REMOVED:
                log.info("删除子节点:" + event.getData().getPath());
                break;
            case CONNECTION_LOST:
                log.info("连接丢失");
                break;
            case CONNECTION_SUSPENDED:
                log.info("连接被挂起");
                break;
            case CONNECTION_RECONNECTED:
                log.info("恢复连接");
                break;
        }
    }
}
